import 'package:earclean/app/config/colors.dart';
import 'package:earclean/app/modules/widget/app_bar_widget.dart';
import 'package:earclean/app/modules/widget/login_button.dart';
import 'package:earclean/app/modules/widget/login_input.dart';
import 'package:earclean/app/routes/app_pages.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

import 'package:get/get.dart';

import '../controllers/login_controller.dart';

class LoginView extends GetView<LoginController> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: ColorConfig.white,
      appBar: AppBarWidget(
        showLeading: false,
        titleStr: '验证码登录',
      ),
      body: Container(
        height: double.infinity,
        child: Column(
          children: [
            SizedBox(height: 60.h),
            Card(
                child: Image.asset('assets/images/logo1.png',
                    width: 100, height: 100)),
            SizedBox(height: 45.h),
            Container(
              margin: EdgeInsets.symmetric(horizontal: 30.w),
              // padding: const EdgeInsets.all(12),
              decoration: BoxDecoration(
                color: const Color(0xFFF4F4F4),
                // border: Border.all(color: ColorConfig.app_main, width: .5),
                borderRadius: BorderRadius.all(Radius.circular(10.r)),
              ),
              child: LoginInput(
                leftWidget: Padding(
                  padding: const EdgeInsets.symmetric(horizontal: 10),
                  child: Image.asset(
                    'assets/images/shoujihao.png',
                    width: 21,
                    height: 28,
                  ),
                ),
                // defaulTiele: "39999912345",
                hint: "请输入手机号",
                autofocus: false,
                keyBoardType: TextInputType.phone,
                inputFormatters: [
                  FilteringTextInputFormatter.digitsOnly,
                  LengthLimitingTextInputFormatter(11)
                ],
                onChanged: (text) {
                  controller.phone = text;
                },
              ),
            ),
            SizedBox(
              height: 30.h,
            ),
            Container(
              width: 1.sw,
              margin: EdgeInsets.symmetric(horizontal: 30.w),
              decoration: BoxDecoration(
                color: const Color(0xFFF4F4F4),
                // border: Border.all(color: ColorConfig.app_main, width: .5),
                borderRadius: BorderRadius.all(Radius.circular(10.r)),
              ),
              child: LoginInput(
                leftWidget: Padding(
                  padding: const EdgeInsets.symmetric(horizontal: 10),
                  child: Image.asset(
                    'assets/images/mima.png',
                    width: 21,
                    height: 28,
                  ),
                ),
                hint: "请输入验证码",
                inputFormatters: [
                  FilteringTextInputFormatter.digitsOnly,
                  LengthLimitingTextInputFormatter(6)
                ],
                obscureText: false,
                keyBoardType: TextInputType.number,
                onChanged: (text) {
                  controller.code = text;
                },
                // focusChanged: (text) {
                //   controller.code.value = text;
                // },
                rightWidget: Obx(() => InkWell(
                      onTap: () {
                        controller.getCode();
                      },
                      child: Container(
                        margin: const EdgeInsets.only(right: 15),
                        child: Text(controller.codeStr.value,
                            style: TextStyle(
                                color: controller.enbleClick.value
                                    ? ColorConfig.app_main
                                    : Color(0xFFC5C8CB),
                                fontSize: 13.sp)),
                      ),
                    )),
              ),
            ),
            SizedBox(
              height: 40.h,
            ),
            Container(
              width: 1.sw,
              height: 45,
              margin: EdgeInsets.symmetric(horizontal: 30.w),
              child: LoginButton(
                "登录",
                enable: true,
                onPressed: controller.send,
              ),
            ),
            const Spacer(),
            Container(
              width: 1.sw,
              margin: EdgeInsets.symmetric(horizontal: 30.w),
              child: Row(
                children: [
                  Obx(() => InkWell(
                      child: Container(
                        padding:
                            EdgeInsets.symmetric(vertical: 5, horizontal: 2),
                        child: Icon(
                          controller.protect.value
                              ? Icons.check_box
                              : Icons.check_box_outline_blank,
                          size: 20,
                          color: ColorConfig.app_main,
                        ),
                      ),
                      onTap: controller.changeAgree)),
                  const SizedBox(
                    width: 5,
                  ),
                  Text.rich(TextSpan(children: [
                    TextSpan(
                        text: '同意',
                        recognizer: TapGestureRecognizer()
                          ..onTap = () {
                            controller.changeAgree();
                          },
                        style: TextStyle(
                            fontSize: 13.sp,
                            color: ColorConfig.body1_txt_color)),
                    TextSpan(
                        text: '《用户协议》',
                        recognizer: TapGestureRecognizer()
                          ..onTap = () {
                            Get.toNamed(Routes.WEB, arguments: {
                              "title": '用户协议',
                              "url":
                                  'https://iamz.jiliol.net/LegalDocuments/UserAgreement.html',
                            });
                          },
                        style: TextStyle(
                            fontSize: 13.sp, color: ColorConfig.app_main)),
                    TextSpan(
                        text: '、',
                        style: TextStyle(
                            fontSize: 13.0.sp,
                            color: ColorConfig.subtitle_text)),
                    TextSpan(
                        text: '《隐私政策》',
                        recognizer: TapGestureRecognizer()
                          ..onTap = () {
                            Get.toNamed(Routes.WEB, arguments: {
                              "title": '隐私政策',
                              "url":
                                  'https://iamz.jiliol.net/LegalDocuments/PrivacyPolicy.html',
                            });
                          },
                        style: TextStyle(
                            fontSize: 12.sp, color: ColorConfig.app_main)),
                  ]))
                ],
              ),
            ),
            SizedBox(
              height: 40.h,
            ),
          ],
        ),
      ),
    );
  }
}
